;BayiQ.push (Make_pair (TX, Ty)); Vis[tx][ty] =true; the } the } - } - the intMainvoid) {//HDU 2612 Find a the while(SCANF ("%d%d", n, m) = =2) { the for(intI=1; ii) { thescanf ("%s", Maze[i] +1); - for(intj=1; jj) { the if(Maze[i][j] = ='Y') SX = i, sy =J; the if(Maze[i][j] = ='M') ex = i, EY =J; the }94 } the bfs_y (); Bfs_m (); the intAns =INF; th
problem DescriptionPass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.Yifenfei's home is on the countryside, but Merceki's home is in the center of the city. So Yifenfei made arrangements and Merceki to meet at a KFC. There is many KFC in Ningbo, they want to choose one and the total time to it is most smallest.Now give your a Ningbo map, Both Yifenfei and Merceki can move up, do
Topic Link: Find A-toThe topic is not difficult, a few days ago, at that time prepared to write two-way BFS, and then deal with the details of some problems, to catch up with something on hold. Rewrite this evening, no two-way, with two times BFS search, and two-way BFS almost the same principle. It's just a little hole in the problem, you need to be careful.1.Y cannot go through M. M cannot go through Y. In other words, Y and M are squares that can be thought of as walls.2. KFC must be both Y a
This is completely a review of previous knowledge... some familiar methods gradually emerged when I was writing ........--
In fact, the questions are very watery... but for the sake of my wa, I posted it ....
HDU 1241
# Include
HDU 2612
I can't brush too many questions at night, so my mind is dizzy... this question is wa to death. wa to death ....
First, the array of the result (KFC) is reduced, so that only maxn is available. In fact,
Find A-toTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 6157 Accepted Submission (s): 2052Problem Descriptionpass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.Yifenfei's home is on the countryside, but Merceki's home is in the center of the city. So Yifenfei made arrangements and Merceki to meet at a KFC. There is many KFC i
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2612
Q: It takes the shortest time for Y and m to go to the same KFC (there may be multiple KFC instances)
My method is to search for the sum of the shortest time of two people from KFC. The only thing that hurts is the first few of TLE's. Yes.
/** Danceonly*/#include
Find A-to
Time limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d %i64 U
Submit
Status
Practice
HDU 2612
DescriptionPass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.
Yifenfei's home is on the countryside, but Merceki's home is in the center of the city. So Yifenfei made arrangements and Merceki to meet at a KFC
HDU-2612-Find a way
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2612
Calculate the sum of the distance between the two points and KFC to minimize it. Use BFS twice to obtain the shortest distance between the two points and each KFC, and then find the minimum and minimum values.
# Include
] [flag] = in. time;For (I = 0; I {Cur. x = in. x + dir [I] [0];Cur. Y = in. Y + dir [I] [1];If (Map [cur. x] [cur. Y]! = '#' Judge (cur. X, cur. y )){Mark [cur. x] [cur. Y] = 1;Cur. Time = in. Time + 11;Q. Push (cur );}}}Return 1;}Int main (){Int I, j, Sx, Sy, dx, Dy, Min, Q;While (scanf ("% d", N, M )! = EOF){Min = inf;For (I = 1; I Scanf ("% s", map [I] + 1 );For (I = 1; I For (j = 1; j For (q = 0; q Dis [I] [J] [Q] = inf;For (I = 1; I For (j = 1; j {If (Map [I] [J] = 'y '){Memset (mark, 0
one of the KFC. Sure there is always has a KFC that can let them meet.Sample Input4 4y.#@.....#. @.. M4 4y.#@.....#. @#. M5 5[email protected].#....#...@. m.#...#Sample Output668866Code:#include #include#include#include#include#includeusing namespacestd;#defineINF 0x3f3f3f3f#defineN 210structnode{intx, y, step;};intN, M, A[n][n], dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};CharG[n][n];intVis[n][n];voidBFS (node S,intnum) {node p, q; Queuep; Q.push (s); memset (Vis,0,sizeof(VIS)); VIS[S.X][S.Y]=
Two persons (Y and M) to meet at the ' @ ', there is an indefinite ' @ ' in the picture;Do the BFS once for everyone, then enumerate each ' @ ' position#include "stdio.h" #include "string.h" #include "queue" using namespace std;const int Inf=0x7fffffff;const int dir[4][2]={ {1,0},{-1,0},{0,1},{0,-1}};struct node{int x,y,t;}; int Y_n,y_m,m_n,m_m,n,m;char str[210][210];int sum[210][210],mark[210][210];int Min (int a,int b) {if (aHDU 2612 Water BFS
Find A-toTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 4854 Accepted Submission (s): 1650Problem Descriptionpass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.Yifenfei's home is on the countryside, but Merceki's home is in the center of the city. So Yifenfei made arrangements and Merceki to meet at a KFC. There is many KFC in
Idea: A question of pleasure than all do not explain the topic is good, let me re-understand the effectiveness of BFS. In fact, the idea is very easy, is to traverse the next two people to each ' @ ' distance, save it and then see which of the shortest line, the key problem isdata structure, that is, the storage and operation of the method. At first, my idea was to map the distance from each point to the walking person to the coordinates of the point, but I stuck in the distance, but I al
() - { A while(cin>>n>>L) { + for(intI=1; i) the for(intj=1; j){ -Cin>>A[i][j]; $ if(a[i][j]=='Y'){//record the position of Y theycurx=i; theycury=J; the } the Else if(a[i][j]=='M'){//record M's position -mcurx=i; inmcury=J; the } the } About intTmin =999999999; theBFS (Ycurx,ycury);//begin breadth-first search with (Ycurx,ycury) as a starting point the for(intI=1; i) the
"Y" and "M ' two people to a KFC (denoted by" @ "on the map) the minimum time and how much they need for the map to N*m. They take 11 minutes each step.You can start with Y and M, respectively. BFS to save the time to each KFC and finally see which KFC's time and the smallest.#include Find A-toProblem Descriptionpass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.Yifenfei's home i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.